|
mruby 4.0.0
mruby is the lightweight implementation of the Ruby language
|

Go to the source code of this file.
Classes | |
| struct | REnv |
| Proc class. More... | |
| struct | RProc |
Macros | |
| #define | MRB_ENV_SET_LEN(e, len) |
| #define | MRB_ENV_LEN(e) |
| #define | MRB_ENV_CLOSE(e) |
| #define | MRB_ENV_ONSTACK_P(e) |
| #define | MRB_ENV_BIDX(e) |
| #define | MRB_ENV_SET_BIDX(e, idx) |
| #define | MRB_ENV_SET_VISIBILITY(e, vis) |
| #define | MRB_ENV_VISIBILITY(e) |
| #define | MRB_ENV_VISIBILITY_BREAK_P(e) |
| #define | MRB_ENV_COPY_FLAGS_FROM_CI(e, ci) |
| #define | MRB_ASPEC_REQ(a) |
| #define | MRB_ASPEC_OPT(a) |
| #define | MRB_ASPEC_REST(a) |
| #define | MRB_ASPEC_POST(a) |
| #define | MRB_ASPEC_KEY(a) |
| #define | MRB_ASPEC_KDICT(a) |
| #define | MRB_ASPEC_BLOCK(a) |
| #define | MRB_ASPEC_NOBLOCK(a) |
| #define | MRB_PROC_CFUNC_FL 128 |
| #define | MRB_PROC_CFUNC_P(p) |
| #define | MRB_PROC_CFUNC(p) |
| #define | MRB_PROC_STRICT 256 |
| #define | MRB_PROC_STRICT_P(p) |
| #define | MRB_PROC_ORPHAN 512 |
| #define | MRB_PROC_ORPHAN_P(p) |
| #define | MRB_PROC_ENVSET 1024 |
| #define | MRB_PROC_ENV_P(p) |
| #define | MRB_PROC_ENV(p) |
| #define | MRB_PROC_TARGET_CLASS(p) |
| #define | MRB_PROC_SET_TARGET_CLASS(p, tc) |
| #define | MRB_PROC_SCOPE 2048 |
| #define | MRB_PROC_SCOPE_P(p) |
| #define | MRB_PROC_NOARG 4096 /* for MRB_PROC_CFUNC_FL, aspec == MRB_ARGS_NONE() */ |
| #define | MRB_PROC_NOARG_P(p) |
| #define | MRB_PROC_ALIAS 8192 |
| #define | MRB_PROC_ALIAS_P(p) |
| #define | MRB_PROC_CASPEC_MASK 0xfc07fu /* bits 0-6 and 14-19 */ |
| #define | mrb_proc_ptr(v) |
| #define | mrb_cfunc_env_get(mrb, idx) |
| #define | MRB_METHOD_FUNC_FL (1 << 24) |
| #define | MRB_METHOD_PUBLIC_FL 0 |
| #define | MRB_METHOD_PRIVATE_FL (1 << 25) |
| #define | MRB_METHOD_PROTECTED_FL (1 << 26) |
| #define | MRB_METHOD_VDEFAULT_FL ((1 << 25) | (1 << 26)) |
| #define | MRB_METHOD_VISIBILITY_MASK ((1 << 25) | (1 << 26)) |
| #define | MRB_METHOD_FUNC_P(m) |
| #define | MRB_METHOD_FUNC(m) |
| #define | MRB_METHOD_FROM_FUNC(m, fn) |
| #define | MRB_METHOD_FROM_PROC(m, pr) |
| #define | MRB_METHOD_PROC_P(m) |
| #define | MRB_METHOD_PROC(m) |
| #define | MRB_METHOD_UNDEF_P(m) |
| #define | MRB_METHOD_VISIBILITY(m) |
| #define | MRB_SET_VISIBILITY_FLAGS(f, v) |
| #define | MRB_METHOD_SET_VISIBILITY(m, v) |
| #define | MRB_METHOD_CFUNC_P(m) |
| #define | MRB_METHOD_CFUNC(m) |
Functions | |
| mrb_bool | mrb_env_unshare (mrb_state *, struct REnv *, mrb_bool noraise) |
| static uint32_t | mrb_proc_compress_aspec (mrb_aspec aspec) |
| static mrb_aspec | mrb_proc_decompress_caspec (uint32_t flags) |
| static void | mrb_proc_set_cfunc_aspec (struct RProc *p, mrb_aspec aspec) |
| struct RProc * | mrb_proc_new (mrb_state *, const mrb_irep *) |
| struct RProc * | mrb_proc_new_cfunc (mrb_state *, mrb_func_t) |
| struct RProc * | mrb_closure_new_cfunc (mrb_state *mrb, mrb_func_t func, int nlocals) |
| struct RProc * | mrb_proc_new_cfunc_with_env (mrb_state *mrb, mrb_func_t func, mrb_int argc, const mrb_value *argv) |
| mrb_value | mrb_proc_cfunc_env_get (mrb_state *mrb, mrb_int idx) |
| mrb_value | mrb_load_proc (mrb_state *mrb, const struct RProc *proc) |
| void | mrb_vm_ci_env_clear (mrb_state *mrb, mrb_callinfo *ci) |
| It can be used to isolate top-level scopes referenced by blocks generated by mrb_load_string_cxt() or similar called before entering the mruby VM (e.g. | |
| void | mrb_vm_ci_proc_set (mrb_callinfo *ci, const struct RProc *p) |
| struct RClass * | mrb_vm_ci_target_class (const mrb_callinfo *ci) |
| void | mrb_vm_ci_target_class_set (mrb_callinfo *ci, struct RClass *tc) |
| struct REnv * | mrb_vm_ci_env (const mrb_callinfo *ci) |
| void | mrb_vm_ci_env_set (mrb_callinfo *ci, struct REnv *e) |
See Copyright Notice in mruby.h
| #define MRB_ASPEC_BLOCK | ( | a | ) |
| #define MRB_ASPEC_KDICT | ( | a | ) |
| #define MRB_ASPEC_KEY | ( | a | ) |
| #define MRB_ASPEC_NOBLOCK | ( | a | ) |
| #define MRB_ASPEC_OPT | ( | a | ) |
| #define MRB_ASPEC_POST | ( | a | ) |
| #define MRB_ASPEC_REQ | ( | a | ) |
| #define MRB_ASPEC_REST | ( | a | ) |
| #define mrb_cfunc_env_get | ( | mrb, | |
| idx ) |
| #define MRB_ENV_BIDX | ( | e | ) |
| #define MRB_ENV_CLOSE | ( | e | ) |
| #define MRB_ENV_COPY_FLAGS_FROM_CI | ( | e, | |
| ci ) |
| #define MRB_ENV_LEN | ( | e | ) |
| #define MRB_ENV_ONSTACK_P | ( | e | ) |
| #define MRB_ENV_SET_BIDX | ( | e, | |
| idx ) |
| #define MRB_ENV_SET_LEN | ( | e, | |
| len ) |
| #define MRB_ENV_SET_VISIBILITY | ( | e, | |
| vis ) |
| #define MRB_ENV_VISIBILITY | ( | e | ) |
| #define MRB_ENV_VISIBILITY_BREAK_P | ( | e | ) |
| #define MRB_METHOD_CFUNC | ( | m | ) |
| #define MRB_METHOD_CFUNC_P | ( | m | ) |
| #define MRB_METHOD_FROM_FUNC | ( | m, | |
| fn ) |
| #define MRB_METHOD_FROM_PROC | ( | m, | |
| pr ) |
| #define MRB_METHOD_FUNC | ( | m | ) |
| #define MRB_METHOD_FUNC_P | ( | m | ) |
| #define MRB_METHOD_PROC | ( | m | ) |
| #define MRB_METHOD_PROC_P | ( | m | ) |
| #define MRB_METHOD_SET_VISIBILITY | ( | m, | |
| v ) |
| #define MRB_METHOD_UNDEF_P | ( | m | ) |
| #define MRB_METHOD_VISIBILITY | ( | m | ) |
| #define MRB_PROC_ALIAS_P | ( | p | ) |
| #define MRB_PROC_CFUNC | ( | p | ) |
| #define MRB_PROC_CFUNC_P | ( | p | ) |
| #define MRB_PROC_ENV | ( | p | ) |
| #define MRB_PROC_ENV_P | ( | p | ) |
| #define MRB_PROC_NOARG_P | ( | p | ) |
| #define MRB_PROC_ORPHAN_P | ( | p | ) |
| #define MRB_PROC_SCOPE_P | ( | p | ) |
| #define MRB_PROC_SET_TARGET_CLASS | ( | p, | |
| tc ) |
| #define MRB_PROC_STRICT_P | ( | p | ) |
| #define MRB_PROC_TARGET_CLASS | ( | p | ) |
| #define MRB_SET_VISIBILITY_FLAGS | ( | f, | |
| v ) |
|
extern |
It can be used to isolate top-level scopes referenced by blocks generated by mrb_load_string_cxt() or similar called before entering the mruby VM (e.g.
from main()). In that case, the ci parameter should be mrb->c->cibase.
#include <mruby.h>
#include <mruby/compile.h>
#include <mruby/proc.h>
int
main(int argc, char **argv)
{
mrb_state *mrb;
mrb_ccontext *cxt;
mrb_value blk, ret;
mrb = mrb_open();
cxt = mrb_ccontext_new(mrb);
blk = mrb_load_string_cxt(mrb, "x, y, z = 1, 2, 3; proc { [x, y, z] }", cxt);
mrb_vm_ci_env_clear(mrb, mrb->c->cibase);
mrb_load_string_cxt(mrb, "x, y, z = 4, 5, 6", cxt);
ret = mrb_funcall(mrb, blk, "call", 0);
mrb_p(mrb, ret); // => [1, 2, 3]
// => [4, 5, 6] if `mrb_vm_ci_env_clear()` is commented out
mrb_ccontext_free(mrb, cxt);
mrb_close(mrb);
return 0;
}
The top-level local variable names stored in mrb_ccontext are retained. Use also mrb_ccontext_cleanup_local_variables() at the same time, if necessary.